<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../../_template.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="centro">
        <h:form>   
            <p:outputLabel value="Nota Fiscal" style="font-size: x-large; margin-left: 25px" styleClass="labelInserir" /> 
            <p:fieldset styleClass="fieldsetInsert" style=" margin-left: 25px; width: 85%">
                <p:messages />
                <p:commandButton value="Novo" action="incluirNotaFiscal" icon="ui-icon-plus" ajax="false" styleClass="btnNovo" style="margin-bottom: 20px; margin-left: 25px"/> 
                <h:outputLabel style="text-align: right; margin-left: 690px; color: #99a699;" value="Total de registros: #{notaFiscalBean.notasFiscais.size()}" 
                               rendered="#{not empty notaFiscalBean.notasFiscais}"/>
                <p:dataTable styleClass="dados" value="#{notaFiscalBean.notasFiscais}" var="nf" emptyMessage="Nenhum registro encontrado!" style="margin-left: -75px">
                    <p:column headerText="Número" style="text-align: center" >
                        <h:outputText value="#{nf.numero}" />
                    </p:column>
                    <p:column  headerText="Data de Emissão" style="text-align: center" >
                        <h:outputText value="#{nf.dataEmissao}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Tipo" style="text-align: center"  >
                        <h:outputText value="#{nf.tipoNotaFiscal.descricao}" />
                    </p:column>
                    <p:column  headerText="Cliente" >
                        <h:outputText value="#{nf.cliente.nome}" />
                    </p:column>
                    <p:column  headerText="Valor Bruto" style="text-align: right" >
                        <h:outputText value="#{nf.valorBruto}" >
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </h:outputText>
                    </p:column>
                    <p:column  headerText="Valor Retido" style="text-align: right" >
                        <h:outputText value="#{nf.valorBruto * nf.retencao}" >
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </h:outputText>
                    </p:column>
                    <p:column  headerText=" Valor Imposto Único" style="text-align: right" >
                        <h:outputText value="#{nf.valorBruto * nf.aliquotaImpostoUnico}" >
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </h:outputText>
                    </p:column>
                    <p:column  headerText="Valor Líquido" style="text-align: right" >
                        <h:outputText value="#{nf.valorBruto - (nf.valorBruto * nf.retencao) - (nf.valorBruto * nf.aliquotaImpostoUnico)}" >
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Data do Vencimento" style="text-align: center" >
                        <h:outputText value="#{nf.dataVencimento}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </p:column>                
                    <p:column style="width: 10px;" headerText="Excluir">
                        <center>
                            <p:commandButton icon="ui-icon-trash" action="#{notaFiscalBean.remover(nf)}" update="@all">
                                <p:confirm header="Confirmação" icon="ui-icon-alert" 
                                           message="Na exclusão desta Nota Fiscal o crédito em conta será revertido. Deseja continuar?"/>
                            </p:commandButton>
                        </center> 
                    </p:column>
                </p:dataTable><br />
                <p:confirmDialog global="true" showEffect="fade" id="Confirmação" >
                    <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                    <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                </p:confirmDialog>
            </p:fieldset>
        </h:form>
    </ui:define>
</ui:composition>
